using UnityEngine;
using System;
using System.Collections;

[AddComponentMenu("TagMachine/Game Modes/Arena Shrink")]
public class GameModeArenaShrink : GameModeClassic 
{
	public string ArenaTag 		= "Arena";
	public float SizeShrink 	= 0.08f;

	private GameObject m_Arena 	= null;

	// Initialization
	protected override void SetupFromPreferences()
	{
		base.SetupFromPreferences();

		if ( PlayerPrefs.HasKey( "SizeShrink" ) )
		{
			SizeShrink = PlayerPrefs.GetFloat( "SizeShrink" );
		}
	}

	protected override void ClearPreferences()
	{
		base.ClearPreferences();
		
		PlayerPrefs.DeleteKey( "SizeShrink" );
	}

	protected override void Start()
	{
		m_Arena = GameObject.FindWithTag( ArenaTag );

		if ( m_Arena == null )
		{
			Debug.LogError("No arena found!!!");
		}

		base.Start();
	}

	// Wolf Change
	public override void SwitchWolf( PlayerEntity _NewWolf )
	{
		// Arena has new size
		if ( CurrentWolf != null && CurrentWolf != _NewWolf &&
			m_Arena != null )
		{
			m_Arena.transform.localScale 		= m_Arena.transform.localScale - Vector3.one * SizeShrink;

			if ( m_Arena.transform.localScale.x < SizeShrink )
			{
				m_Arena.transform.localScale 	= Vector3.one * SizeShrink;
			}
		}

		base.SwitchWolf( _NewWolf );
	}

	protected override void EndRound()
	{
		if ( m_Arena != null )
		{
			m_Arena.transform.localScale 		= Vector3.one;
		}

		base.EndRound();
	}
}
